package com.gtl.meishi.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.gtl.meishi.R;
import com.gtl.meishi.adapter.CollectionAdapter;
import com.gtl.meishi.bean.Collection;
import com.gtl.meishi.dao.CollectionDao;

import java.util.List;

public class CollectionActivity extends AppCompatActivity {
    private ListView mListView;
    private List<Collection> listCollections;
    private CollectionDao dao;
    private CollectionAdapter  adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collection);
        mListView = (ListView) findViewById(R.id.listview_collection);
        dao=new CollectionDao(Collection.class,this);

        listCollections=dao.queryAll();
        adapter=new CollectionAdapter(this,listCollections);
        mListView.setAdapter(adapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                toast("单击查看详情");

            }
        });

        mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
              toast("长按删除");

                return true;
            }
        });
    }


    public  void  toast(String msg){
        Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();

    }
}
